package main

import (
	"fmt"
	"sync"
	"time"
)

var scene sync.Map

func main() {
	go start(1)
	go start(2)
	time.Sleep(time.Second * 20)
}

func start(i int) {
	lock1(i)
	fmt.Println(i, "start")
	time.Sleep(time.Second * 2)
	fmt.Println(i, "do")
	scene.Delete(1)
}

func lock1(i int) {
	ticker := time.NewTicker(time.Second * 1) //定义一个1秒间隔的定时器
	defer ticker.Stop()
	for {
		//if i > 5 {
		//	break
		//}
		_, ok := scene.Load(1)
		if !ok {
			break
		}
	}
	scene.Store(1, struct{}{})
}
